/*
 * �?�?:
 * 1.Tạo (code) 1 file test.txt có 20 dòng (tùy ý)  

     Xuất dữ liệu từ file trên (1) ra màn hình   

     Xuất dữ liệu từ file (1) ra một file C/test/test.txt  

     Xuất dữ liệu từ file (1) ra 1 file: text.dat
 */
package Bai1;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class HomeWork {
	private List<String> list;
	
	//constructor
	public HomeWork() {
		list = new ArrayList<String>();
	}
	
	//gettor
	
	//settor
	
	//nhap du lieu tu ban phim
	public void enterDataL() {
		Scanner scanner = new Scanner(System.in);
		String n;
		for(int i = 0; i < 5; i++) {
			System.out.print("Line " + i + ": ");
				n = scanner.nextLine();
				list.add(n);
		}
	}
	
	//ham ghi file
	public void writeFile() {
		
		FileOutputStream fOut;
		
		//ghi file test.txt
		try {
			//ghi file
			fOut = new FileOutputStream("test.txt");
			PrintWriter pW = new PrintWriter(fOut,true);
			
			System.out.print("File test.txt: ");
			for(int i = 0; i < list.size(); i++) {
				System.out.print(list.get(i) + "\t");
				pW.println(list.get(i));
			}
			
			fOut.close();
			pW.close();
		}
		catch (Exception exc) {
			System.out.println("Can not write to this file");
		}
		
		System.out.println();
		
		//ghi file test.dat
		try {
			//ghi file
			fOut = new FileOutputStream("test.dat");
			PrintWriter pW = new PrintWriter(fOut,true);
			
			System.out.print("File test.dat: ");
			for(int i = 0; i < list.size(); i++) {
				System.out.print(list.get(i));
				pW.println(list.get(i));
			}
			
			fOut.close();
			pW.close();
		}
		catch (Exception exc) {
			System.out.println("Can not write to this file");
		}
	}

}
